package com.lucker.common.util;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

public class SignUtil {
	
	
	public static String getSignature(org.json.JSONObject jsonData, String timestamp) {
	    Map<String, String> sortedParams = new TreeMap<>();
	    sortedParams.put("timestamp", timestamp);
	    if (jsonData != null) {
	        Iterator<String> iterator = jsonData.keys();
	        while (iterator.hasNext()) {
	            String key = iterator.next();
	            String value = jsonData.optString(key);
	            sortedParams.put(key.toLowerCase(), value);
	        }
	    }
	    StringBuilder data = new StringBuilder();
	    Set<Map.Entry<String, String>> entry = sortedParams.entrySet();
	    for (Map.Entry<String, String> params : entry) {
	        data.append(params.getKey()).append('=').append(params.getValue());
	    }
	    data.append(CommonStr.CLIENT_SECRET_KEY);

	    return MD5.passmd5(data.toString());
	}

}
